#include<bits/stdc++.h>

using namespace std;

class Solution {
public:
    int findMinHeightTreesHeight(int st, unordered_map<int, unordered_set<int>> &edges) {
        unordered_map<int, int> f;
        function<int(int)> bfs = [&](int start)->int
            {
                unordered_set<int> visited;
                visited.emplace(start);
                queue<int> q;
                q.push(start);
                int x = start;
                while (!q.empty()) {
                    x = q.front(); q.pop();
                    for (auto &y : edges[x]) {
                        if (visited.count(y)) continue;
                        // else
                        visited.emplace(y);
                        q.push(y);
                        f[y] = x;
                    }
                }
                return x;
            };
        int u = bfs(st);
        int v = bfs(u);

        int length = 0;
        f[u] = -1;
        while (v!=-1)
        {
            ++length;
            v = f[v];
        }
        return length / 2;
    }
};


int main() {
    unordered_map<int, unordered_set<int>> edges;
    int n;
    cin >> n;
    int st = 0;
    while (--n) {
        int u, v;
        cin >> u >> v;
        st = u;
        edges[u].emplace(v);
        edges[v].emplace(u);
    }
    cout << Solution().findMinHeightTreesHeight(st, edges) << endl;
}

